package com.mushuilingfeng.ddd.user.cover;

import com.mushuilingfeng.ddd.user.bo.*;
import com.mushuilingfeng.ddd.user.domain.org.vo.OrgApplyRequest;
import com.mushuilingfeng.ddd.user.domain.user.dto.MobileLoginDto;
import com.mushuilingfeng.ddd.user.domain.user.dto.PasswordLoginDto;
import com.mushuilingfeng.ddd.user.domain.user.dto.UserQueryDto;
import com.mushuilingfeng.ddd.user.domain.user.entity.User;
import com.mushuilingfeng.ddd.user.domain.user.enums.LoginTypeEnum;
import com.mushuilingfeng.ddd.user.domain.user.vo.UserPersonInfo;
import com.mushuilingfeng.ddd.user.vo.UserVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.Date;
import java.util.List;

/**
 * @author 沐水淋风
 * @date 2024/10/6
 */
@Mapper(imports = {LoginTypeEnum.class, Date.class})
public interface IDataCover {
    IDataCover INSTANCE = Mappers.getMapper(IDataCover.class);
    
    default UserVO toUserVO(User user) {
        return toUserVO(user, user.getPersonInfo());
    }
    
    /**
     * 尽量不要使用此方法，尽量使用toUserVO(User user)
     */
    @Mapping(source = "user.id", target = "userId")
    @Mapping(expression = "java(user.getGender().getDesc())", target = "gender")
    @Mapping(expression = "java(user.getStatus().getCode())", target = "status")
    UserVO toUserVO(User user, UserPersonInfo personInfo);
    
    List<UserVO> toUserVOList(List<User> userList);
    
    UserQueryDto toUserQueryDto(UserQueryBO bo);
    
    @Mapping(expression = "java(LoginTypeEnum.PASSWORD)", target = "loginType")
    PasswordLoginDto toPasswordLoginDto(UserPasswordLoginBO bo);
    
    @Mapping(expression = "java(LoginTypeEnum.MOBILE)", target = "loginType")
    MobileLoginDto toMobileLoginDto(MobileLoginBO bo);
    
    @Mapping(source = "bo", target = "applyOrg")
    @Mapping(target = "applyTime", expression = "java(new Date())")
    OrgApplyRequest toOrgApplyRequest(OrgApplyBO bo);
    
    UserPersonInfo toUserPersonInfo(UserPersonInfoBO bo);
}
